package internal

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

type IDUriPathParam struct {
	ID uint64 `uri:"id"`
}

type Resp struct {
	Status int         `json:"status"`
	Msg    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

func writeSuccessResp(c *gin.Context, data interface{}) {
	if data == nil {
		data = map[string]string{"SUCCESS": "OK"}
	}
	c.PureJSON(200, Resp{Status: 0, Msg: "ok", Data: data})
}

func writeFailResp(c *gin.Context, status int, msg string) {
	c.JSON(500, Resp{Status: status, Msg: msg})
}

type AsiaTime time.Time

var bjLocation, err = time.LoadLocation("Asia/Shanghai")

func (t AsiaTime) MarshalJSON() ([]byte, error) {
	tt := (time.Time)(t).In(bjLocation)
	stamp := fmt.Sprintf("\"%s\"", tt.Format("2006-01-02 15:04:05"))
	return []byte(stamp), nil
}
